// components/choose_package/choose_package.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    active: {
      type: Boolean,
      value: false
    },
    type_: {
      type: String,
      value: 'all'
    },
    data_: {
      type: Object,
      value: null
    },
    typeArr: {
      type: Array,
      value: null
    },
    typeState: {
      type: Array,
      value: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    number: 1
  },

  observers: {
    // 'active, active,data_'() {}
  },
  /**
   * 组件的方法列表
   */
  methods: {
    exitFun() {
      this.setData({
        active: false
      })
    },
    // 加入购物车
    add_cart() {},
    // 确认订单
    submit_order() {
      let data_ = this.data.data_
      let datas = []
      let userData = {}
      userData.ID = this.data.data_.goodsID
      this.data.typeState.some((item, index) => {
        if (item) {
          userData.type = this.data.typeArr[index]
        }
        return item
      })
      userData.number = this.data.number
      data_.userData = userData
      this.setData({
        data_
      })
      datas.push(this.data.data_)
      if (userData.type) {
        wx.navigateTo({
          url: '../../pages/payment/payment?datas=' + JSON.stringify(datas),
        })
      }
    },
    // 规格 item 单击
    item_touchend(e) {
      let touchindex = e.currentTarget.dataset.index
      let typeState = []
      this.data.typeState.forEach((item, index) => {
        if (touchindex == index) {
          typeState.push(true)
        } else {
          typeState.push(false)
        }
      })
      this.setData({
        typeState
      })
    },
    // 购买件数 - 按钮
    addbtnFun() {
      this.setData({
        number: this.data.number - 1
      })
    },
    // 购买件数 + 按钮
    minusbtnFun() {
      this.setData({
        number: this.data.number + 1
      })
    }
  }
})